<?php

class Board_Space
{
    private $_name = '';
    private $_type = '';
    private $_next = null;
    private $_board = null;
    private $_group = null;

    public function __construct($name, $board)
    {
        $this->setName($name);
        $this->setBoard($board);
    }

    public function __toString()
    {
        return $this->getName();
    }

    public function getName()
    {
        return $this->_name;
    }

    public function setName($name)
    {
        $this->_name = $name;
    }

    public function getBoard()
    {
        return $this->_board;
    }

    public function setBoard($board)
    {
        $this->_board = $board;
    }

    public function next($space = null)
    {
        if ($space) {
            $this->_next = $space;
        }

        return $this->_next;
    }

    public function pass($player)
    {
        $this->onPass($player);

        $player->getPiece()->setSpace($this->next());
    }

    public function land($player)
    {
        $this->onLand($player);

        $player->getPiece()
               ->setSpace($player->getPiece()
                                 ->getSpace());
    }

    public function onPass($player)
    {
        // space subclasses can override this event to implement
        // behaviour that will occur when this space is passed
    }

    public function onLand($player)
    {
        // space subclasses can override this event to implement
        // behaviour that will occur when this space is landed on
    }
}
